import sys
from pathlib import Path
current_file_path = Path(__file__)
project_root = current_file_path.parent.parent.parent
sys.path.append(str(project_root))

import simpy
import logging

from model import (
    Node,
    recorder
)

from model.mobility import (
    Position,
    ConstantSpeed,
    LinearMobility,
    RandomWaypointMobility,
    TrajectoryMobility
)

logger = logging.getLogger('Test')

def set_logger_level(name, level):
    logger = logging.getLogger(name)
    logger.setLevel(level)

def setup_logging():
    logging.basicConfig(
        level=logging.WARNING,
        format='%(name)12s - %(levelname)5s - %(message)s',
    )
    set_logger_level('Node', logging.DEBUG)

if __name__ == '__main__':

    setup_logging()
    
    logger.info(f"Starting mobility test simulation...")
    
    env = simpy.Environment()
    
    # 节点1线性移动
    n1 = Node(env, 1)
    dest = Position(1000, 0, 500)
    n1.set_mobility(LinearMobility(ConstantSpeed(15), dest))
    
    # 节点2轨迹移动
    n2 = Node(env, 2)
    waypoints = [
        Position(500, 0, 0),
        Position(500, 500, 0),
        Position(0, 500, 0),
        Position(0, 1000, 0),
        Position(500, 1000, 0),
    ]
    n2.set_mobility(TrajectoryMobility(
        ConstantSpeed(25),
        waypoints=waypoints,
        loop=True
    ))

    # 运行仿真
    env.run(100)
    logger.info("Simulation finished.")
    recorder.save('RadioTestSecond.json')